package org.myOrg.spetrum.spectrumStruct;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import org.myOrg.spetrum.combination.Tuple;


public class TupleAnalyseStruct {
	private Tuple tuple;
	private List<TupleAnalyseStruct> directChilds;
	private List<TupleAnalyseStruct> directFathers;
	private boolean passOrFail;
	private boolean isTested;
	private double suspicion;
	
	
	public TupleAnalyseStruct(){
		directChilds = new ArrayList<TupleAnalyseStruct>();
		directFathers = new ArrayList<TupleAnalyseStruct>();
		passOrFail = false;
		isTested = false;
		suspicion = 1.0;
	}
	
	public TupleAnalyseStruct(Tuple tuple){
		this.tuple = tuple;
		directChilds = new ArrayList<TupleAnalyseStruct>();
		directFathers = new ArrayList<TupleAnalyseStruct>();
		passOrFail = false;
		isTested = false;
		suspicion = 0;
	}
	
	public void addSuspicion(double suspicion){
		this.suspicion += suspicion;
	}

	public void addDirectChild(TupleAnalyseStruct child) {
		this.directChilds.add(child);
	}

	public void addDirectFather(TupleAnalyseStruct father) {
		this.directFathers.add(father);
	}
	
	public double getTestValuable(){
		if(!this.isTested)
		return this.suspicion;		
		return 0;
	}
	

	public void setSuspicion(double suspicion) {
		this.suspicion = suspicion;
	}

	public double getSuspicion() {
		return suspicion;
	}

	public void setTested(boolean isTested) {
		this.isTested = isTested;
	}

	public boolean isTested() {
		return isTested;
	}

	public void setPassOrFail(boolean passOrFail) {
		this.passOrFail = passOrFail;
	}

	public boolean isPassOrFail() {
		return passOrFail;
	}

	public List<TupleAnalyseStruct> getDirectFathers() {
		return directFathers;
	}

	public List<TupleAnalyseStruct> getDirectChilds() {
		return directChilds;
	}

	public Tuple getTuple() {
		return tuple;
	}
	
	public List<TupleAnalyseStruct> getAllChilds(){
		HashSet<TupleAnalyseStruct> result = new HashSet<TupleAnalyseStruct>();
        result.addAll(directChilds);
        
        Iterator<TupleAnalyseStruct> itr = directChilds.iterator();
		while(itr.hasNext()){
			TupleAnalyseStruct child = itr.next();
			result.addAll(child.getAllChilds());
		}
		return new ArrayList<TupleAnalyseStruct>(result);
	}
	
	public List<TupleAnalyseStruct> getAllFathers(){
		HashSet<TupleAnalyseStruct> result = new HashSet<TupleAnalyseStruct>();
        result.addAll(directFathers);
        
        Iterator<TupleAnalyseStruct> itr = directFathers.iterator();
		while(itr.hasNext()){
			TupleAnalyseStruct father = itr.next();
			result.addAll(father.getAllFathers());
		}
		return new ArrayList<TupleAnalyseStruct>(result);
	}
	
}
